const baseurl='https://m.douban.com/rexxar/api/v2/'
Page({
  data:{
    start:0,
    count:5
  },
  // 写入传参就会收到
  onLoad(option){//option 获取前一个页面(index.js)传过来的
    this.setData({//全局变量
      type:option.type,
      id:option.id
      
    })
    let xq = baseurl+option.type+'/'+option.id//详情
    let bq = baseurl+option.type+'/'+option.id+'/tags?count=10'//标签
    let dp = baseurl+option.type+'/'+option.id+'/interests?start='+this.data.start+'&count='+this.data.count//短评
    // console.log(option)
    // let {type,id}=option
    // this.setData({
    //   type,id
    // })
    wx.request({
      url: xq,
      success:res=>{
        console.log('xq',res)
        // join 把  genres  数组连接起来
        let mygenres=res.data.genres.join('/')
        let myactors=res.data.actors.slice(0,3).map(v=>{
          return v.name
        }).join('/')
        this.setData({
          xq:res.data,
          mygenres,
          myactors
        })
      }
    }),
    wx.request({
      url: bq,
      success:res=>{
        console.log('bq',res)
        this.setData({
          bq:res.data
        })
      }
    }),
    wx.request({
      url: dp,
      success:res=>{
        console.log('dp',res)
        let dptotal = res.data.total
        this.setData({
          dp:res.data.interests,
          dptotal
        })
      }
    })
  },
  onReachBottom(){
    this.setData({
      start:this.data.start+this.data.count
    })
    let dp = baseurl+this.data.type+'/'+this.data.id+'/interests?start='+this.data.start+'&count='+this.data.count//短评
    wx.request({
      url: dp,
      success:res=>{
        let newdp = res.data.interests
        let dp = this.data.dp.concat(newdp)
        this.setData({
          dp
        })
      }
    })
  }
})